<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>脚本列表</title>
    
	<link rel="stylesheet" type="text/css" href="<%=basePath%>/css/common.css" />
    <link rel="stylesheet" href="<%=basePath%>/js/jquery-tablesorter/themes/blue/style.css" type="text/css" media="print, projection, screen" />
    <script type="text/javascript" src="<%=basePath%>/js/jquery-1.8.3.js"></script>
    <script type="text/javascript" src="<%=basePath%>/js/jquery-tablesorter/jquery.tablesorter.min.js"></script>
    <style type="text/css">
      fieldset,table,tr,td {margin:0; padding:0;}
      td {padding:0 5px 0 10px;}
      form label {font-weight:bold;}
      input[type="button"]{width:60px};
    </style>
    
    <script type="text/javascript">
	
	$(document).ready(function() { 
       	$("#resultTable").tablesorter({
       		headers:{0:{sorter:false},
       			1:{sorter:false}},
       			widgets: ['zebra']
       	});
       	
       	$("#btn_pageUp").click(function(){
			var page = $("#page").val();
			$("#page").val(parseInt(page) - 1);
			$("#groupForm").submit();
       	});
       	
       	$("#btn_pageDown").click(function(){
       		var page = $("#page").val();
			$("#page").val(parseInt(page) + 1);
			$("#groupForm").submit();
       	});

        $("#btn_insert").click(function(){
        	var entityId = $("#entityId").val();
            location.href = "<%=basePath%>manage/etlScript?act=insert&entityId="+entityId;
        });
        
        $("#btn_search").click(function(){
            $("#page").val(1);
            $("#groupForm").submit();
        });
        
        $("#btn_return").click(function(){
        	var size = $("#entitySize").val();
        	 location.href = "<%=basePath%>manage/etl?act=getPage&size="+size;
        });

        $("#btn_change").click(function(){
            var selectpage = parseInt($("#selectPage").val());
            var page = parseInt($("#page").val());
            if(page == selectpage) return;
            $("#page").val(parseInt(selectpage));
            $("#groupForm").submit();
        });
        
        $.ajaxSetup ({ cache:false });
	});  
	
	function del(id,entityId) {
		if(confirm("确定删除该对象？") != 1) return;
		location.href = "<%=basePath%>manage/etlScript?act=delete&entityId="+entityId+"&id="+id;
	}
  </script>
  </head>
  
  <body>
  <div>
  	<table id="resultTable"  class="tablesorter">
  	<input type="hidden" name="entitySize" id= "entitySize" value="${entitySize }" />
  	<input type="hidden" name="entityId" id= "entityId" value="${entityId }" />
     <thead>
          <tr>
              <th width="150px;">脚本序列</th>
              <th width="250px;">脚本内容</th>
              <th width="150px;">出错是否跳过</th>
              <th width="150px;">创建时间</th>
              <th width="150px;">修改时间</th>
              <th width="150px;">模式名</th>
              <th width="150px;">实体名</th>
              <th width="150px;">操作</th>
          </tr>
          </thead>
          <c:forEach items="${list}" var="script" varStatus="status">
          <tr>
		  	  <td>${script.scriptSeq }</td>
		  	  <td style="white-space: nowrap;">${script.scriptStr }</td>
		  	  <td>${script.errorPast }</td>
		  	  <td>${script.createDate }</td>
		  	  <td>${script.updateDate }</td>
		  	  <td>${script.entitySchema }</td>
		  	  <td>${script.entityName }</td>
		  	  <td>
		  	  	<a href="<%=basePath%>manage/etlScript?act=update&scriptId=${script.scriptId}&entityId=${script.entityId}">修改</a>
		  	  	<a href=# onclick="javascript:del('${script.scriptId}','${script.entityId }'); return false;">删除</a>
		  	  </td>
          </tr>
          </c:forEach>
    </table>
  </div>
  
  <div>
      <div style="float:left;">
		<input id="btn_insert" type="button" value="新增" /> <input id="btn_return" type="button" value="返回" />
      </div>

      <div style="text-align:right;">
        <c:if test="${page <= 1}"><input type="button" disabled="disabled" id="btn_pageUp" value="上一页"/></c:if>
        <c:if test="${page > 1}"><input type="button" id="btn_pageUp" value="上一页"/></c:if>
        <c:if test="${page >= totalpage}"><input type="button" id="btn_pageDown" disabled="disabled" value="下一页"/></c:if>
        <c:if test="${page < totalpage}"><input type="button" id="btn_pageDown" value="下一页"/></c:if>
        共${totalpage}页/共${count}条
        <select id="selectPage" style="width: auto;">
            <c:forEach var="i" begin="1" end="${totalpage}">
                <option id="${i}" <c:if test="${i == page}">selected="selected"</c:if>>${i}</option>
            </c:forEach>
        </select>
        <input id="btn_change" type="button" value="转至" />
      </div>
  </div>
 </body>
</html>
